package com.sawgdev.android.bokuiki.common.gps;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MapOverlay extends Overlay {

    private GeoPoint geoPointFrom = null;
    private GeoPoint geoPointTo = null;

    public MapOverlay(GeoPoint from, GeoPoint to) {
        geoPointFrom = from;
        geoPointTo   = to;
    }

    /**Overlay(abstratクラス)を継承したHogeOverlayクラスにdrawメソッドを実装 */
    @Override
    public void draw(Canvas canvas, MapView mapView, boolean isShadow) {
        super.draw(canvas, mapView, isShadow);

        //Projection#toPixels()で変換した場合の結果格納用
        Point pxPointFrom = new Point();
        Point pxPointTo   = new Point();

        //GePointからPointに変換
        Projection projection = mapView.getProjection();
        projection.toPixels(geoPointFrom, pxPointFrom);
        projection.toPixels(geoPointTo, pxPointTo);

        Paint paint = new Paint();

        //Lineの両端を丸く
        paint.setStrokeCap(Paint.Cap.ROUND);

        //Lineのつなぎ目を丸く
        paint.setStrokeJoin(Paint.Join.ROUND);

        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.RED);
        paint.setStrokeWidth(4);
        paint.setAlpha(255);
        paint.setAntiAlias(true);

        //4.drawメソッド内で、Canvas#drawLine()を使って始点から終点に線を引く
        canvas.drawLine(pxPointFrom.x, pxPointFrom.y, pxPointTo.x, pxPointTo.y, paint);
    }
}